package com.soso.base.util.json;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.soso.base.exception.unchecked.GeneralExceptionHandler;

public class DateTimeDeserializer implements JsonDeserializer<Date> {
	private final static SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");

	public final Date deserialize(JsonElement json, Type typeOfT,
			JsonDeserializationContext context) throws JsonParseException {
		Date date=null;
		try {
			date = sdf.parse(json.getAsJsonPrimitive().getAsString());
		} catch (ParseException e) {
			GeneralExceptionHandler.handle(e);
		}
		return date;
	}
}
